<template>
  <div>
    <el-card style="width: 500px; margin: 50px auto">
      <h1 style="width:100px;margin: 15px auto">用户反馈</h1>
      <el-form :model="messageForm" ref="loginForm" :rules="rules" label-width="160px">
        <el-form-item prop="userName" label="标题:">
          <el-input v-model="messageForm.title" style="width: 220px" placeholder="标题"/>
        </el-form-item>
        <el-form-item prop="password" label="内容:">
          <el-input v-model="messageForm.content" style="width: 220px" placeholder="内容"/>
        </el-form-item>
        <el-form-item>
          <!-- <el-button type="primary" @click="$router.push('/register')">注册</el-button> -->
          <el-button type="primary" @click="submit">反馈</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>


export default {
  name: "login",
  data() {
    return {
      messageForm: {
        title: '',
        content: '',
      },
      // rules: {
      //   username: [{required: true, message: '用户名不能为空', trigger: 'blur'}],
      //   password: [{required: true, message: '密码不能为空', trigger: 'blur'}]
      // }
    }
  },
  methods: {
    submit(){
      this.$refs.loginForm.validate(v => {
        if (v) {
          // TODO 用户登录 跳转到导航页
          this.$store.dispatch('user/login', this.loginForm)
            .then(() => {
              this.$router.push({ path: this.$route.query.redirect || '/' })
            })
            .catch(() => {
              this.$message.error('登录失败');
            })
          // console.log(this.loginForm)
          // this.$router.push({ path: this.$route.query.redirect || '/' })
        } else {
          return false
        }
      })
    }
  },
}
</script>

<style scoped>

</style>
